package com.twu.biblioteca.ui;

import com.twu.biblioteca.data.BookDAO;
import com.twu.biblioteca.data.MovieDAO;

/**
 * Created by florian on 26/12/13.
 */
public class MainScreenController implements ScreenController {
    protected final ScreenControllerFactory screenControllerFactory;
    protected final BibliotecaUI ui;
    protected final BookDAO bookDAO;
    protected final MovieDAO movieDAO;

    public MainScreenController(ScreenControllerFactory screenControllerFactory,BibliotecaUI ui,BookDAO bookDAO,MovieDAO movieDAO) {
        this.screenControllerFactory = screenControllerFactory;
        this.ui = ui;
        this.bookDAO = bookDAO;
        this.movieDAO = movieDAO;
        showMenu();
    }

    protected void showMenu() {
        ui.showMainMenu();
    }

    @Override
    public ScreenController processCommand(String line) {
        if (line.equals("q")) {
            return null;
        }else if (line.equals("1")) {
            ui.listBooks(bookDAO.getAllAvailableItems());
            return this;
        } else if (line.equals("4")) {
            ui.listMovies(movieDAO.getAllAvailableItems());
            return this;
        } else if (line.equals("10")) {
            return screenControllerFactory.createLoginController();
        } else {
            return invalidOption();
        }
    }

    protected ScreenController invalidOption() {
        ui.showInvalidMenuOptionMessage();
        return this;
    }


}
